package com.zengqingfa.imp.demo.rest;

import com.zengqingfa.imp.demo.dto.Emp;
import com.zengqingfa.imp.demo.service.EmpService;
import com.zengqingfa.imp.demo.service.ExportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @fileName: EmpController
 * @author: zengqf3
 * @date: 2021-3-3 13:36
 * @description:
 */

@RestController
@RequestMapping("/emp/")
public class EmpController {

    @Autowired
    private EmpService empService;
    @Autowired
    private ExportService exportService;

    @GetMapping(value = "findAll")
    public List<Emp> findAll() {
        List<Emp> empList = empService.findAll();
        return empList;
    }

    @GetMapping(value = "findAll2")
    public List<Emp> findAll2() {
        List<Emp> empList = empService.findAll2();
        return empList;
    }

    @GetMapping(value = "findByPage")
    public List<Emp> findByPage(@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        List<Emp> empList = empService.findByPage(pageNo, pageSize);
        return empList;
    }

    @GetMapping(value = "findById")
    public Emp findById(@RequestParam Integer id) {
        Emp emp = empService.findById(id);
        return emp;
    }


    @GetMapping(value = "batchExport")
    public void batchExport(HttpServletRequest request, HttpServletResponse response) throws InterruptedException {
        exportService.batchExport(response);
    }
}
